﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class CartDAO:IData<Cart> 
 	{
		public CartDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Cart item, int t) {
			 return connec.ExecuteNonQuery("sp_Cart", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Cart.c_id, item.id), new SqlParameter("@" + Cart.c_customerId, item.customerId),
				 new SqlParameter("@" + Cart.c_credit, item.credit), new SqlParameter("@" + Cart.c_bank, item.bank),
				 new SqlParameter("@" + Cart.c_total, item.total), new SqlParameter("@" + Cart.c_status, item.status),
				 new SqlParameter("@" + Cart.c_orderId, item.orderId), new SqlParameter("@" + Cart.c_create_on, item.create_on)); 
		}

		public override Cart GetItem(IDataReader dr)
		{
			Cart obj = new Cart();
			obj.id = Convert.ToInt64(dr[Cart.c_id]);
			obj.customerId = Convert.ToInt64(dr[Cart.c_customerId]);
			obj.credit = Convert.ToString(dr[Cart.c_credit]);
			obj.bank = Convert.ToString(dr[Cart.c_bank]);
			obj.total = Convert.ToDecimal(dr[Cart.c_total]);
			obj.status = Convert.ToInt32(dr[Cart.c_status]);
			obj.orderId = Convert.ToInt32(dr[Cart.c_orderId]);
			obj.create_on = Convert.ToDateTime(dr[Cart.c_create_on]);
			return obj;
		}

		public override List<Cart> GetAll()
		{
			return GetAll("select * from " + Cart.b_Cart, CommandType.Text);
		}

		public override Cart GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
